<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>注册</title>
</head>

<body>
<div>
    <form action="main_01.html" method="post" autocomplete="off" onsubmit="return checkAll()">
        <table>
            <tr>
                <td>登录名:</td>
                <td>
                    <input type="text" id="name" name="name"
                           onblur="checkName()" placeholder="请填写用户名">
                    <!--                    <span style="text-decoration-color: red">*</span>-->
                </td>
                <td id="name_msg">
                    用户名以小写字母开头,可以包含大小写字母和数字;
                </td>
            </tr>
            <tr>
                <td>登录密码:</td>
                <td>
                    <input type="password" name="pwd" id="pwd" onblur="checkpwd()" placeholder="请输入密码">
                </td>
                <td id="pwd_msg">密码至少6位至多12位</td>
            </tr>
            <tr>
                <td>确认密码:</td>
                <td>
                    <input type="password" name="rpwd" id="rpwd" onblur="checkrpwd()" placeholder="请确认密码">
                </td>
                <td id="rpwd_msg">必须与原密码相同</td>
            </tr>
            <tr>
                <td>
                    <button type="submit" id="tijiao">提交</button>
                </td>
            </tr>
        </table>
    </form>
</div>
<script type="text/javascript">
    function $(id) {
        return document.getElementById(id);
    }

    function checkName() {
        var name = $("name").value;
        var reg = /^[a-z][a-zA-Z0-9]{5,11}$/;
        var msg = "× 登录名格式有误!";
        var flag = false;
        if (reg.test(name)) {
            msg = "√ ";
            flag = true;
        }
        $("name_msg").innerHTML = msg;
        return flag;
    }

    function checkpwd() {
        var name = $("pwd").value;
        var reg = /^[a-zA-Z0-9]{6,12}$/;
        var msg = "× 密码格式有误!";
        var flag = false;
        if (reg.test(name)) {
            msg = "√ ";
            flag = true;
        }
        $("pwd_msg").innerHTML = msg;
        return flag;
    }

    function checkrpwd() {
        var name = $("pwd").value;
        var name1 = $("rpwd").value;
        var msg = "× 两次密码不一致";
        var flag = false;
        if (name1 == name) {
            msg = "√ ";
            flag = true;
        }
        $("rpwd_msg").innerHTML = msg;
        return flag;
    }
    function checkAll() {
        var flag = false;
        if(checkName()&&checkpwd()&&checkrpwd()){
            flag = true;
        }else {
            alert("您的信息有误");
        }
        return flag;
    }
</script>
</body>
</html>